<template>
  <div v-if="!isPay" class="flex" style="width:100%;">
    <div class="flex" style="flex-wrap: wrap; flex:1;">
      <div v-for="(item, index) in list" :key="index" class="numberBox" @click="onGetNumber(item)">{{ item }}</div>
      <div class="numberBox flex justify-center align-center" @click="onClearNumber()">
        <img src="@/assets/payView/chehui.png" alt="" class="numberBoxImg" />
      </div>
    </div>
    <div class="flex flex-direction">
      <div v-if="isMeberPay" class="meberBut" @click="onSendMember">会员卡</div>
      <div style="flex: 1;">
        <div class="sendBut" @click="onSend">
          <div
            v-if="!isMeberPay"
          >立即</div>
          <div>支付</div>
        </div>
      </div>
    </div>
  </div>
  <div v-else>
    <div class="flex" style="flex-wrap: wrap; flex:1;">
      <div v-for="(item, index) in list" :key="index" class="numberBoxTwo" @click="onGetNumber(item)">{{ item }}</div>
      <div class="numberBoxTwo flex justify-center align-center" @click="onClearNumber()">
        <img src="@/assets/payView/chehui.png" alt="" class="numberBoxImg" />
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
export default {
  props: ['isMeberPay', 'isPay'],
  setup(props, context) {
    const list = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.'] // 键盘值
    const numInput = ref('') // 输入值
    function onGetNumber(str) {
      if (numInput.value.indexOf('.') !== -1 && str === '.') return
      if (numInput.value.indexOf('.') !== -1 && (numInput.value.length - numInput.value.indexOf('.')) >= 3) return
      if (!numInput.value && str === '.') {
        numInput.value = '0.'
      } else {
        numInput.value += str
      }
      context.emit('getPay', numInput.value)
    }
    function onClearNumber() {
      const str = numInput.value
      numInput.value = str.substring(0, str.length - 1)
      context.emit('getPay', numInput.value)
    }
    return {
      list,
      numInput,
      onGetNumber,
      onClearNumber
    }
  },
  methods: {
    onSend() {
      const payNum = Number(this.numInput)
      this.$emit('pay', payNum)
    },
    onSendMember() {
      const payNum = Number(this.numInput)
      this.$emit('payMember', payNum)
    }
  }
}
</script>

<style scoped>
.sendBut{
  width: 180px;
  height: 100%;
  background: #F8B202;
  font-size: 46px;
  color: #FFFFFF;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.numberBox{
  box-sizing: border-box;
  width: 33.33%;
  height: 107px;
  line-height: 107px;
  text-align: center;
  background: #FFFFFF;
  border: 1px solid #F2F2F2;
  font-size: 28px;
}
.numberBoxImg{
  width: 40px;
  height: 40px;
  display: block;
}
.numberBoxTwo{
  box-sizing: border-box;
  width: 33.33%;
  height: 96px;
  line-height: 96px;
  text-align: center;
  background: #FFFFFF;
  border: 1px solid #F2F2F2;
  font-weight: 700;
}
.meberBut{
  width: 177px;
  height: 130px;
  line-height: 130px;
  background: #EF3B14;
  font-size: 36px;
  text-align: center;
  color: #FFFFFF;
}
</style>
